package com.message;

import com.message.notify.RegisterNotifyMessage;
import com.message.ping.PingMessage;
import com.message.register.RpcRegisterRequest;
import com.message.register.RpcRegisterResponse;
import com.message.rpc.RpcRequestMessage;
import com.message.rpc.RpcResponseMessage;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

import static com.message.constant.MessageType.*;

/**
 * @author linyu.dai
 * @project rpc
 * @description
 * @creat 2022/11/27 12:00:51
 */
@Data
public abstract class Message {

    private static final Map<Integer, Class<? extends Message>> messageMap = new HashMap<>();

    static {
        //注册信息
        messageMap.put(RPC_REGISTER_REQUEST, RpcRegisterRequest.class);
        messageMap.put(RPC_REGISTER_RESPONSE, RpcRegisterResponse.class);
        //rpc远程调用
        messageMap.put(RPC_REQUEST_MESSAGE, RpcRequestMessage.class);
        messageMap.put(RPC_RESPONSE_MESSAGE, RpcResponseMessage.class);
        messageMap.put(PING_MESSAGE, PingMessage.class);
        messageMap.put(REGISTER_NOTIFY_MESSAGE, RegisterNotifyMessage.class);
    }

    public static Class<? extends Message> getMessageClass(int messageType){
        return messageMap.get(messageType);
    }

    //消息类型
    private int messageType;

    //序列化id
    private int sequenceId;

    /**
     * @Author linyu.dai
     * @Description 需要子类提供
     * @Date 2022/11/27 14:38
     * @Param [messageType]
     * @return void
     */
    public abstract int getMessageType();
}
